﻿#pragma once

#include <winerror.h>
#include <string>

namespace ifire::dx {

class DxException {
public:
  DxException() = default;
  DxException(HRESULT hr, const std::string& functionName,
      const std::string& filename, int lineNumber);

  std::string ToString() const;

  HRESULT ErrorCode = S_OK;
  std::string FunctionName;
  std::string Filename;
  int LineNumber = -1;
};

#ifndef HASSERT
#define HASSERT(x)                                                             \
  {                                                                            \
    HRESULT hr__ = (x);                                                        \
    std::string wfn = std::string(__FILE__);                                   \
    if (FAILED(hr__)) {                                                        \
      throw DxException(hr__, #x, wfn, __LINE__);                              \
    }                                                                          \
  }
#endif

} // namespace ifire::dx